import 'package:flutter/material.dart';



class RotatingIcon extends StatefulWidget {

  final IconData icon;
  final Color iconColor;
  final double iconSize;

  const RotatingIcon({super.key, required this.icon, this.iconColor = Colors.red, this.iconSize = 48});

  @override
  _RotatingIconState createState() => _RotatingIconState();
}

class _RotatingIconState extends State<RotatingIcon> with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    )..repeat(); // 使动画无限循环
    // 你也可以选择使用repeat(reverse: true)来让图标来回旋转
  }

  @override
  Widget build(BuildContext context) {
    return RotationTransition(
      turns: _controller,
      child: Icon(
        widget.icon,
        color: widget.iconColor,
        size: widget.iconSize, // 设置图标大小
      ),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}